<template>
  <a-card>
    <div class="home">
      <div class="searchNav" style="display: flex; justify-content: flex-end">
        <!-- <a-button
        class="button"
        icon="el-icon-plus"
        type="primary"
        style="margin-left: 0"
        :loading="loading"
        @click="dialogConfirm"
        >新增</a-button
      > -->
        <div class="searchParams" style="display: flex; padding-bottom: 10px">
          <div>
            <radioGroup @radioChange="radioChange" @complete="radioComplete" />
          </div>

          <div>
            <!-- <span style="height: 40px;line-height: 40px;float:left;font-size: 16px;">日期类型：</span> -->
            <el-radio-group v-model="dtVal" style="margin-bottom:16px;margin-left:10px;margin-right:4px" size="small">
              <el-radio-button label="发货"></el-radio-button>
              <el-radio-button label="签收"></el-radio-button>
            </el-radio-group>
          </div>
          <el-date-picker v-model="range" type="daterange" align="right" unlink-panels range-separator="-"
            valueFormat="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"
            style="width:290px" size="small">
          </el-date-picker>
          <!-- <a-input
            style="margin: 0 10px;"
            class="input"
            v-model="queryParam.keyword"
            placeholder="请输入货单编号/签收人"
            @keydown.enter.native="getDataList"
          ></a-input> -->
          <searchTip v-model="queryParam.keyword" style="margin: 0 10px" placeholder="请输入货单编号/签收人"
            :list="searchTipResultList" @enterKeyDown="getDataList" @change="toGetSearchTipList" @blur="keywordBlurFun"
            @select="selectSearchTipFun" />
          <a-button class="button" @click="getDataList" style="background-color: #1890ff; color: #fff">查询</a-button>
          <a-button class="button" @click="exportExcel" style="background-color: #1890ff; color: #fff">导出</a-button>
        </div>
      </div>
      <el-tabs v-model="activeName" class="tabs" @tab-click="handleClick">
        <el-tab-pane v-for="tItem in tabList" :key="tItem.label" :label="tItem.label" :name="tItem.name">
          <el-table :data="tableData" style="width: 100%" height="calc(100vh - 340px)" v-loading="loading">
            <!-- <el-table-column prop="CompanyName" label="所属公司" width="250">
          </el-table-column> -->
            <el-table-column prop="BillId" label="编号" width="180px"> </el-table-column>
            <el-table-column prop="Customer" label="客户"> </el-table-column>
            <el-table-column prop="CreateTime" label="发货日期" width="120">
              <template slot-scope="scope">
                {{ scope.row.CreateTime ? scope.row.CreateTime.substring(0, 10) : '' }}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="ContactPersonName" label="收货人">
            <template slot-scope="scope">
              {{ scope.row.ContactPersonName }}
              {{
                scope.row.ContactPersonName && scope.row.CustomerPhone
                  ? "/"
                  : ""
              }}
              {{ scope.row.CustomerPhone }}
            </template>
          </el-table-column> -->
            <el-table-column prop="CreateTime" label="签收日期" width="120">
              <template slot-scope="scope">
                {{ scope.row.SigningDate ? scope.row.SigningDate.substring(0, 10) : '' }}
              </template>
            </el-table-column>
            <el-table-column prop="FullName" label="签收人">
              <template slot-scope="scope">
                {{ scope.row.FullName }}
                {{ scope.row.FullName && scope.row.ReceiptPhone ? '/' : '' }}
                {{ scope.row.ReceiptPhone }}
              </template>
            </el-table-column>
            <el-table-column prop="TotalQuantity" label="总数量">
              <template slot-scope="scope">
                {{ scope.row.TotalQuantity ? scope.row.TotalQuantity.toFixed(4) : '' }}
              </template>
            </el-table-column>
            <el-table-column prop="TotalMoney" label="总金额">
              <template slot-scope="scope">
                {{ scope.row.TotalMoney ? formatNumber(scope.row.TotalMoney.toFixed(2)) : '' }}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="CustomerPhone" label="签收手机号" width="130">
            <template slot-scope="scope">
              {{
                scope.row.CustomerPhone != "暂无" ? scope.row.CustomerPhone : ""
              }}
            </template>
          </el-table-column> -->
            <el-table-column prop="Status" label="状态" width="100" align="center">
              <template slot-scope="scope">
                <el-tag class="tableEltag"
                  v-if="scope.row.Status == 0 && (tItem.name == 'first' || tItem.name == '0')">待签收</el-tag>
                <el-tag class="tableEltag" v-if="scope.row.Status == 1 && (tItem.name == 'first' || tItem.name == '1')"
                  type="success">已签收</el-tag>
                <el-tag class="tableEltag" v-if="scope.row.Status == 2 && (tItem.name == 'first' || tItem.name == '2')"
                  type="danger">已拒收</el-tag>
                <el-tag class="tableEltag" v-if="scope.row.Status == 3 && (tItem.name == 'first' || tItem.name == '3')"
                  type="warning">有差异</el-tag>
                <el-tag class="tableEltag" v-if="scope.row.Status == 4 && (tItem.name == 'first' || tItem.name == '4')"
                  type="danger">已作废</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="标记" width="100" align="center">
              <template slot-scope="scope">
                <el-tag class="tableEltag" v-for="item in scope.row.Tag ? scope.row.Tag.split(',') : []" :key="item">
                  {{ item }}
                </el-tag>
              </template>
            </el-table-column>

            <el-table-column label="备注" width="100" align="center">
              <template slot-scope="scope">
                <div>{{ scope.row.Memo }}</div>
              </template>
            </el-table-column>

            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <!-- <el-popconfirm
                v-if="scope.row.Status == 4"
                confirm-button-text="是"
                canca-button-text="否"
                canca-button-type=""
                title="是否使用新模板进行重置?"
                @confirm="resetStart(scope.row, 'confirm')"
                @cancel="resetStart(scope.row, 'cancel')"
                ><el-link slot="reference" type="primary" :underline="false"
                  >重置</el-link
                >
              </el-popconfirm> -->
                <el-link type="primary" :underline="false" @click="handelOpen(scope.row)">标记 &nbsp;&nbsp; </el-link>
                <!-- <el-link
                  v-if="scope.row.Status < 3"
                  type="primary"
                  :underline="false"
                  class="linkmargin"
                  :disabled="scope.row.Isevidence"
                  @click="toChain(scope.row)"
                >存证 &nbsp;&nbsp;
                </el-link> -->
                <el-link class="linkmargin" v-if="scope.row.Status == 0" type="primary" :underline="false"
                  @click="openwaybillForm(scope.row)">编辑 &nbsp;&nbsp;
                </el-link>
                <el-link v-if="scope.row.Status != 4" type="primary" :underline="false" class="linkmargin"
                  @click="openNewPage(scope.row, 'view')">查看 &nbsp;&nbsp;
                </el-link>
                <!-- {{ scope.row.Tag.split(",").some((item) => item == "已确认") }} -->
                <el-popconfirm v-if="scope.row.Status == 3 &&
              (!scope.row.Tag ? true : !scope.row.Tag.split(',').some((item) => item == '已确认'))
              " confirm-button-text="确认" canca-button-text="取消" canca-button-type="" title="此操作将同意当前回执单差异,确认继续吗?"
                  @confirm="differentConfrim(scope.row)"><el-link slot="reference" type="primary"
                    style="margin-right:10px;" class="linkmargin" :underline="false">确认</el-link>
                </el-popconfirm>

                <el-link v-if="scope.row.Status" type="primary" :underline="false" class="linkmargin"
                  @click="handleDownload(scope.row)">下载 &nbsp;&nbsp;
                </el-link>
                <el-link v-if="scope.row.Status == 0" type="danger" class="linkmargin" :underline="false"
                  @click="handleInvalidate(scope.row)">作废
                </el-link>
                <!-- 存证 -->
                <!-- <el-link
              type="primary"
              :underline="false"
              class="linkmargin"
              @click="handleSaveConfirmation(scope.row)"
              >存证
            </el-link> -->
              </template>
            </el-table-column>
          </el-table>
          <el-pagination layout="total,prev, pager, next,sizes" :total="pagination.total"
            :current-page="pagination.current" :page-size="pagination.pageSize" :page-sizes="pagination.pageSizeOptions"
            style="text-align: right; margin-top: 8px; padding: 0" @current-change="currentChange"
            @size-change="handleSizeChange">
          </el-pagination>
        </el-tab-pane>
      </el-tabs>
      <el-dialog title="选择模板" width="30%" :visible.sync="dialogVisible">
        <el-select v-model="templateId" placeholder="请选择模板" style="width: 100%">
          <el-option v-for="(item, index) in templateList" :key="item.Id" :label="item.TemName"
            :value="index"></el-option>
        </el-select>
        <div slot="footer" class="dialog-footer">
          <a-button @click="dialogVisible = false">取 消</a-button>
          <a-button type="primary" @click="dialogConfirm">确 定</a-button>
        </div>
      </el-dialog>
      <el-dialog title="添加标记" width="30%" :visible.sync="inputDialogVisible" :close-on-click-modal="false">
        <el-tag :key="tag" v-for="tag in dynamicTags" closable :disable-transitions="false" @close="handleClose(tag)"
          @click="selectTag(tag)">
          {{ tag }}
        </el-tag>
        <a-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
          @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
        </a-input>
        <a-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加标记</a-button>
        <div style="margin-bottom: 10px">已选标记</div>
        <div>
          <el-tag :key="tag" v-for="tag in selectTags" closable :disable-transitions="false"
            @close="handleSelectClose(tag)" type="success">
            {{ tag }}
          </el-tag>
        </div>
        <div slot="footer" class="dialog-footer">
          <a-button @click="inputDialogVisible = false">取 消</a-button>
          <a-button type="primary" @click="inputDialogConfirm">确 定</a-button>
        </div>
      </el-dialog>
      <waybillForm ref="waybillForm" :parentObj="{ ...this }" />
      <a-drawer v-if="jumpId ? true : false" title="送货单" width="850px" placement="right" :closable="false"
        :visible="jumpId ? true : false" @close="() => {
              this.jumpId = null
            }
              ">
        <!-- <SendSMS  :jump="jumpId"></SendSMS> -->
        <iframe style="width: 100%; height: 88vh; border: 0"
          :src="`https://hzq.yoojet.com/#/SendSMSByThirdParty?prop=${jumpId}`"></iframe>
      </a-drawer>
    </div>
    <printCopy ref="printCopy"></printCopy>

    <el-dialog title="导出Excel" :visible.sync="exportFormVisible" width="350px">
      <!-- <div>
        <span>隶属公司：</span>
        <el-select v-model="companyVal" placeholder="请选择隶属公司">
          <el-option v-for="item in companys" :key="item.Id" :label="item.Title" :value="item.Id">
          </el-option>
        </el-select>
      </div> -->


      <el-radio-group v-model="tabVal" style="margin-bottom:16px">
        <el-radio-button label="已签收"></el-radio-button>
        <el-radio-button label="差异"></el-radio-button>
        <el-radio-button label="拒收"></el-radio-button>
        <el-radio-button label="作废"></el-radio-button>
      </el-radio-group>
      <!-- <div>
        <span style="height: 40px;line-height: 40px;float:left;font-size: 16px;">日期类型：</span>
        <el-radio-group v-model="dtVal" style="margin-bottom:16px">
          <el-radio-button label="发货"></el-radio-button>
          <el-radio-button label="签收"></el-radio-button>
        </el-radio-group>
      </div>
      <el-date-picker v-model="range" type="daterange" align="right" unlink-panels range-separator="-"
        valueFormat="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"
        style="width:290px">
      </el-date-picker> -->

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDig">取 消</el-button>
        <el-button type="primary" @click="downloadExcel">确 定</el-button>
      </div>
    </el-dialog>
  </a-card>
</template>

<script>
import radioGroup from '@/components/components/CompanyRadioGroup.vue'
import waybillForm from './waybillForm.vue'
import printCopy from '@/views/ReceiptSign/waybill/printCopy.vue'
import searchTip from '@/components/components/SearchTip.vue'

const downloadFile = (url, downloadName = '') => {
  // console.log(url);
  const link = document.createElement('a')
  fetch(url)
    .then((res) => res.blob())
    .then((blob) => {
      link.href = URL.createObjectURL(blob)
      // console.log(link.href)
      link.download = downloadName
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    })
}
export default {
  companyVal:'',
  name: 'Home',
  components: { radioGroup, waybillForm, printCopy, searchTip },
  data() {
    return {
      companys:[],
      tabVal: '已签收',
      dtVal:'发货',
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      range: [],
      exportFormVisible: false,
      activeName: '1',
      pagination: {
        current: 1,
        pageSize: 25,
        total: 0,
        pageSizeOptions: [25, 50, 100],
      },
      sorter: {
        field: 'CreateTime',
        order: 'desc',
      },
      tableData: [],
      queryParam: { SupplieId: '全部', Status: '1', Condition: 'hzq' },
      keyword: '',
      loading: false,
      dialogVisible: false,
      templateId: '',
      templateList: [],
      tabList: [
        // { label: "全部", name: "first" },
        // { label: "待签收", name: "0" },
        { label: '已签收', name: '1' },
        { label: '差异', name: '3' },
        { label: '拒收', name: '2' },
        { label: '作废', name: '4' },
      ],
      ip: '',
      inputDialogVisible: false,
      inputVisible: '',
      inputValue: '',
      dynamicTags: [],
      selectTags: [],
      rowId: '',
      jumpId: null,
      searchTipResultList: [],
    }
  },
  mounted() {
    // this.getTemplateList()
    this.ip = sessionStorage.getItem('ip')
    this.$httpp
        .post('/Base_Manage/Base_Company/GetDataCompanyDataByWansheng', {})
        .then((res) => {
          if (res.Success) {
            this.companys=res.Data
            if(res.Data.length>0){
              this.companyVal=res.Data[0].Id
            }
            // console.log('------------com--------------',JSON.stringify(this.companys))
          } else {
            this.$message.error(res.Msg)
          }
        })
  },
  computed: {
    height() {
      return document.documentElement.clientHeight * 0.75
    },
  },
  methods: {
    // 千分位格式化
    formatNumber(num) {
      return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    },
    // 弹出导出查询
    exportExcel() {
      this.exportFormVisible = true
    },
    // 关闭导出查询
    cancelDig(){
      this.exportFormVisible = false
      this.tabVal = '已签收'
      this.range=[]
    },
    // 导出操作
    downloadExcel() {
      if(this.range.length<2){
        this.$message.info('请选择日期区间')
        return
      }
            this.$httpp.post('/BO/BillList/ExportExcelByType', {
              Type: this.tabVal,
              DateArea: this.range,
              DateType:this.dtVal,
              CompanyId:this.companyVal
            }, { responseType: 'blob' }).then(res => {
                const url = URL.createObjectURL(res)
                // console.log(url)
                const fileName = this.range[0]+'-'+this.range[1]+this.tabVal+'回执'
                const aTag = document.createElement('a')
                aTag.download = fileName
                aTag.href = url
                aTag.click()
                URL.revokeObjectURL(aTag.href)
                this.$message.success("系统处理完毕正在下载，请稍候...");
                this.cancelDig()
            }).catch(err => {
                this.$message.error(err);
            })
        },
    // 存证
    async toChain(row) {
      // if (!row.ReceiptPhone) return this.$message.error("未获取到签收人信息");
      this.$httpp
        .post('/Base_Manage/Home/AddChain', {
          shipperId: row.Company,
          billId: row.Id,
          body: JSON.stringify(row),
          name: '回执单号:' + row.BillId,
          description: `${row.FullName || ''} ${row.ReceiptPhone}对回执单${row.BillId}签收了`,
          cCusName: row.CustomerName || '',
        })
        .then((res) => {
          if (res.Success) {
            this.$message.success('操作成功')
            row.Isevidence = true
            this.$httpp.post('/BO/BillList/UpdateEvidence?Id=' + row.Id).then(() => { })
          } else {
            this.$message.error(res.Msg)
          }
        })
      // let result = await this.$httpp.chainGet(
      //   "/Chain/auth?id=" + row.ReceiptPhone
      // );
      // if (result.Success)
      //   localStorage.setItem("chainToken", "Bearer " + result.Data);
      // else return this.$message.error("操作失败,请重新尝试");
      // this.$httpp
      //   .chainPost("/Chain", {
      //     shipperId: row.Company,
      //     billId: row.Id,
      //     body: JSON.stringify(row),
      //     name: "回执单号:" + row.BillId,
      //     description: `${row.FullName || ""} ${row.ReceiptPhone}对回执单${
      //       row.BillId
      //     }签收了`,
      //     cCusName: row.CustomerName || "",
      //   })
      //   .then((res) => {
      //     this.$httpp
      //       .post("/BO/BillList/UpdateEvidence?Id=" + row.Id)
      //       .then(() => {
      //         row.Isevidence = true;
      //       });
      //   });
    },
    // 标记
    handelOpen(row) {
      this.rowId = row.Id
      if (row.Tag) this.selectTags = row.Tag.split(',')
      else this.selectTags = []
      let arr = localStorage.getItem('tagList')
      if (!arr) arr = []
      else arr = JSON.parse(arr)
      this.dynamicTags = arr
      this.inputDialogVisible = true
    },
    // 标记保存
    inputDialogConfirm() {
      if (this.inputVisible) {
        const inputValue = this.inputValue
        console.log(this.dynamicTags.findIndex((item) => item == this.inputValue))
        if (inputValue && this.dynamicTags.findIndex((item) => item == this.inputValue) == -1) {
          this.dynamicTags.push(inputValue)
        }
        this.inputValue = ''
      }
      localStorage.setItem('tagList', JSON.stringify(this.dynamicTags))
      if (this.selectTags.length <= 0) {
        return this.$message.error('请至少选择一项')
      }
      this.$httpp
        .post('/BO/BillList/UpdateTag', {
          Id: this.rowId,
          Tag: this.selectTags.join(','),
        })
        .then((res) => {
          if (res.Success) {
            this.$message.success('操作成功')
            this.getDataList()
            this.inputDialogVisible = false
          } else this.$message.error(res.Msg)
        })
    },
    selectTag(tag) {
      console.log(tag)
      const idx = this.selectTags.findIndex((item) => item == tag)
      if (idx == -1) this.selectTags.push(tag)
      else this.selectTags.splice(idx, 1)
    },
    // 标签删除
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },
    // 已选标签删除
    handleSelectClose(tag) {
      this.selectTags.splice(this.selectTags.indexOf(tag), 1)
    },
    // 增加标签
    showInput() {
      this.inputVisible = true
      this.$nextTick((_) => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm() {
      const inputValue = this.inputValue
      if (inputValue && this.dynamicTags.findIndex((item) => item == this.inputValue) == -1) {
        this.dynamicTags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    },
    // 编辑
    openwaybillForm(row) {
      this.$httpp.post('/BO/BillList/GetTheBillData', { id: row.Id }).then((res) => {
        if (res.Success) {
          console.log(res)
          this.$refs.waybillForm.openForm(res.Data, '1', row.Company, '')
        } else {
          this.$message.error(res.Msg)
        }
      })
    },
    // 同意差异
    async differentConfrim(row) {
      this.$httpp.post('/BO/BillList/ConfigSubmit?Id=' + row.Id + '&IP=' + this.ip).then((res) => {
        if (res.Success) {
          this.getDataList()
          this.$message.success('操作成功')
        } else {
          this.$message.error(res.Msg)
        }
      })
      if (row.IsEvidence == true) {
        var res = await this.$httpp.post('/BO/BillList/GetContent?Id=' + row.Id).then()
        this.Content = res.Data
        await this.$httpp
          .post('/Base_Manage/Home/AddChain', {
            shipperId: row.Company,
            billId: row.Id,
            body: res.Data,
            cCusName: row.CustomerName,
            Name: '回执单号:' + row.BillId,
            Description: row.FullName + '提交了回执单差异回执单' + row.BillId,
          })
          .then((res) => console.log(res))
      }
    },
    // 重启
    resetStart(row, type) {
      let url = ''
      if (type == 'confirm') url = '/BO/BillList/WebForm'
      else url = '/BO/BillList/Processing'
      this.$httpp.post(url + '?Id=' + row.Id).then((res) => {
        if (res.Success) {
          this.getDataList()
          this.$message.success('操作成功')
        } else {
          this.$message.error(res.Msg)
        }
      })
    },
    // 重置
    resetTemplate(row) {
      this.$confirm('此操作将改变当前货单模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$httpp.post('/BO/BillList/ResetFormTemplate?Id=' + row.Id + '&CommpayId=' + row.Company).then((res) => {
          if (res.Success) {
            this.$message.success('操作成功')
          } else {
            this.$message.error(res.Msg)
          }
        })
      })
    },
    radioComplete(e) {
      if (e) {
        this.queryParam.SupplieId = e
        this.getDataList()
      }
    },
    // 打开单据页面 'view' | 'downLoad'
    openNewPage(row, type) {
      console.log(row.Id)
      this.$refs.printCopy.openInit(row.Id, type)
      // const token = JSON.parse(localStorage.getItem('ReceiptSign_token')).token
      // this.jumpId = row.Id + '&' + token
      // let isClient = sessionStorage.getItem("client");
      // let url = `${location.href.split("#")[0]}#/SendSMS?prop=${row.Id}`;
      //  if (isClient) {
      //   url = `${location.href.split("#")[0]}#/SendSMSCopy?prop=${row.Id}`;
      // }
      // window.open(url, "_blank");
    },
    // 新增电子回执
    async dialogConfirm() {
      // if (!this.templateId) return this.$message.error("请选择模板");
      if (
        !this.queryParam.SupplieId ||
        this.queryParam.SupplieId.split(',').length > 1 ||
        this.queryParam.SupplieId === '全部'
      ) {
        return this.$message.warning('请选择公司后新增')
      }
      const result = await this.$httpp.post(
        '/Base_Manage/Base_Company/DataIntegrity?CommpayId=' + this.queryParam.SupplieId
      )
      if (!result.Success) return this.$message.error(result.Msg)
      this.loading = true
      this.$httpp.post(`/Base/Base_Template/GetCompanyTemp?CompayId=${this.queryParam.SupplieId}`).then((res) => {
        if (res.Success) {
          this.$refs.waybillForm.openForm(res.Data.Content, '', this.queryParam.SupplieId, res.Data.TemName)
          this.dialogVisible = false
        } else {
          this.$message.error(res.Msg)
        }
        this.loading = false
      })
      // this.$httpp
      //   .post('/Base/Base_Template/GetTemplateDefault', {})
      //   .then((res) => {
      //     if (res.Success) {
      //       this.$refs.waybillForm.openForm(res.Data.Content)
      //       this.dialogVisible = false
      //     } else {
      //       this.$message.error(res.Msg)
      //     }
      //     this.loading = false
      //   })
      // this.$refs.waybillForm.openForm(
      //   // this.templateList[this.templateId].Content
      //   this.templateList[this.templateList.length - 1].Content
      // )
      // this.dialogVisible = false;
    },
    // 公司切换
    radioChange(e) {
      if (e == 'more') return
      this.queryParam.SupplieId = e
      this.getDataList()
    },
    // 页签切换
    handleClick(tab, event) {
      this.pagination = {
        current: 1,
        pageSize: 25,
        total: 0,
        pageSizeOptions: [25, 50, 100],
      }
      this.queryParam.Status = this.activeName + ''
      if (this.activeName == 'first') this.queryParam.Status = ''
      this.getDataList()
    },
    // 下载
    handleDownload(scope) {
      this.openNewPage(scope, 'downLoad')
      // this.$httpp.post('/BO/BillList/GetPDF?id=' + scope.Id).then((res) => {
      //   if (res.Success) {
      //     downloadFile(res.Data, scope.BillId)
      //   } else {
      //     this.$message.error(res.Msg)
      //   }
      // })
    },

    // 存证
    handleSaveConfirmation(scope) {
      console.log('存证', scope)
      this.$message.success('已存证')
    },

    // 作废
    handleInvalidate(scope) {
      this.$confirm('确认要作废本条单据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$httpp.post('/BO/BillList/ToVoid?Billd=' + scope.Id + '&IP=' + this.ip).then((res) => {
          if (res.Success) {
            this.$message.success('操作成功')
            this.getDataList()
          } else {
            this.$message.error(res.Msg)
          }
        })
      })
    },
    // 模板列表
    getTemplateList() {
      this.$httpp.post('/Base/Base_Template/GetDataList', {}).then((res) => {
        if (res.Success) {
          this.templateList = res.Data
        }
      })
    },
    currentChange(page) {
      this.pagination.current = page
      this.getDataList()
    },
    handleSizeChange(lint) {
      this.pagination.pageSize = lint
      this.getDataList()
    },
    getDataList() {
      this.searchTipResultList = [] //清空搜索提示列表
      this.queryParam.DateType=this.dtVal
      
      if(this.range.length==2){
        this.queryParam.StartDate=this.range[0]
        this.queryParam.EndDate=this.range[1]
      }

      this.loading = true
      this.$httpp
        .post('/BO/BillList/GetDataListByDate', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
        })
        .then((resJson) => {
          this.loading = false
          if (resJson.Success) {
            this.tableData = resJson.Data
            if (this.tableData) {
              const pagination = { ...this.pagination }
              pagination.total = resJson.Total
              this.pagination = pagination
            }
          }
        })
    },
    async toGetSearchTipList(e) {
      this.searchTipResultList = []
      this.queryParam.keyword = e
      if (!this.queryParam.keyword) {
        return
      }
      await this.$httpp
        .post('/BO/BillList/GetBillList', {
          PageIndex: 1,
          PageRows: 50,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
        })
        .then((resJson) => {
          if (resJson.Success && this.queryParam.keyword) {
            this.searchTipResultList = resJson.Data.map((e) => e.CustomerName).slice(0, 10)
          } else {
            this.searchTipResultList = []
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    selectSearchTipFun(text) {
      this.queryParam.keyword = text
      this.searchTipResultList = []
      this.getDataList()
    },

    keywordBlurFun() {
      this.searchTipResultList = []
    },
  },
}
</script>
<style lang="less" scoped>
.searchNav .a-button {
  background: #1890ff;
  border-color: #1890ff;
  color: #fff;
}

/deep/.el-radio-button__orig-radio:checked+.el-radio-button__inner {
  color: #fff;
  background-color: #1890ff;
  border-color: #1890ff;
  box-shadow: -1px 0 0 0 #1890ff;
}

/deep/.el-radio-button__inner:hover {
  color: #1890ff;
}

.el-tag {
  margin-right: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}

.button-new-tag {
  margin-bottom: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.input-new-tag {
  width: 90px;
  margin-bottom: 10px;
  // vertical-align: bottom;
}

.tableEltag {
  margin: 0;
}

/deep/ .el-tabs__nav {
  width: 100%;
  background: #fff;
}

/deep/ .el-tab-pane {
  width: 100%;
  background: #fff;
}

/deep/ .el-tabs__item {
  width: 25%;
  text-align: center;
  font-weight: bold;
  padding: 0;
}

/deep/ .el-tabs__item:hover {
  background: #ecf5ff;
}
</style>
